import {IServers} from '../interface/IFace'
import { view_render } from './Functions';
import * as path from 'path'
export class Controller{
    protected _config:IServers;
    protected _ctx;
    constructor(ctx){
        this._ctx = ctx;
        this._config = ctx.config;
    }
    protected _assign:Object={};
    protected get assign():Object{
        return this._assign||{};
    }
    protected set assign(data:Object){
        this._assign = data;
    }
    public async get(){        
    }
    public async gets(){}
    public async save(){}
    public async search(){}
    public async del(){}
    protected display(template?:string){
        if(!template){
            template=`${this._config.Controller}:${this._config.Method}`
        }
        if(template.split(':').length==1){
            template = `${this._config.Controller}:`
        }
        return view_render(template.replace(/:/g,path.sep),this.assign,this._config.view_path)
    }
    public get _isLogined():boolean{
        return this.UID>0
    }
    public get UID(){
        return this._ctx.session('UID')
    }
    public set UID(UID:Number){
        this._ctx.session('UID',UID)
    }
    public session(key:string|null,value?:any){

    }
}